{% extends "bvblogapp/base.html" %}
{% block pageName %}BioVenTurist - Search companies{% endblock %}

{% block queryScript %}

<!--CSS file (default YUI Sam Skin) -->

<!-- Individual YUI CSS files --> 
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.8.0r4/build/paginator/assets/skins/sam/paginator.css"> 
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.8.0r4/build/datatable/assets/skins/sam/datatable.css"> 
<!-- Individual YUI JS files --> 
<script type="text/javascript" src="http://yui.yahooapis.com/2.8.0r4/build/yahoo/yahoo-min.js"></script> 
<script type="text/javascript" src="http://yui.yahooapis.com/2.8.0r4/build/event/event-min.js"></script> 
<script type="text/javascript" src="http://yui.yahooapis.com/2.8.0r4/build/connection/connection-min.js"></script> 
<script type="text/javascript" src="http://yui.yahooapis.com/2.8.0r4/build/datasource/datasource-min.js"></script> 
<script type="text/javascript" src="http://yui.yahooapis.com/2.8.0r4/build/dom/dom-min.js"></script> 
<script type="text/javascript" src="http://yui.yahooapis.com/2.8.0r4/build/element/element-min.js"></script> 
<script type="text/javascript" src="http://yui.yahooapis.com/2.8.0r4/build/paginator/paginator-min.js"></script> 
<script type="text/javascript" src="http://yui.yahooapis.com/2.8.0r4/build/datatable/datatable-min.js"></script> 
<script type="text/javascript" src="http://yui.yahooapis.com/2.8.0r4/build/get/get-min.js"></script> 
<script type="text/javascript" src="http://yui.yahooapis.com/2.8.0r4/build/json/json-min.js"></script> 
<script type="text/javascript" src="http://yui.yahooapis.com/2.8.0r4/build/selector/selector-min.js"></script>


<link type="text/css" rel="stylesheet" href="/bvsearchapp/static/css/bvsearchapp.css" />

<!-- jQuery packed from Google CDN -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

<!-- Freebase controls -->
<link type="text/css" rel="stylesheet" href="/static/css/freebase-controls.css" />
<script src="/static/js/freebase.suggest.js" type="text/javascript"></script>
<!-- Curvy corners jQuery plugin -->
<script type="text/javascript" src="/static/js/jquery.curvycorners.packed.js"></script>
<!-- Facebox jQuery plugin -->
<link href="/bvsearchapp/static/js/facebox.css" media="screen" rel="stylesheet" type="text/css"/>
<script src="/bvsearchapp/static/js/facebox.js" type="text/javascript"></script>

<!-- Load ListFormatter and CompanyNameFormatter -->
<script type="text/javascript" src="/bvsearchapp/static/js/formatters.js"></script>
<script type="text/javascript">function load_info(){return true}</script>
<script type="text/javascript">
    /* Settings */

    var RECORDS_PER_PAGE = 5; // Set the count of records per page
    var BIOVENTURIST_DIR = '/base/bioventurist/';

    /* begin: type_for_freebase_suggest - Return freebase type for specified filter */
    var type_for_freebase_suggest = function(t) {
        TYPES_FOR_FREEBASE_SUGGEST = {
            'name': bioventurist_dir+'science_or_technology_company',
            'has_area_of_expertise': BIOVENTURIST_DIR+'technology_class',
            'products': BIOVENTURIST_DIR+'product',
            'has_develops_treatments_for_disease': BIOVENTURIST_DIR+'bv_medical_condition',
        };
        return TYPES_FOR_FREEBASE_SUGGEST[t];
    }
    /* end: type_for_freebase_suggest */

  var not_default_columns = [
        {key: 'key', label: 'Database keys', formatter: ListFormatter},
        {key: '_business_company_founded', label: 'Date Founded', formatter: ListFormatter},
        {key: '_business_company_place_founded', label: 'Place Founded', formatter: ListFormatter},
        {key: '_business_company_headquarters', label: 'Headquarters', formatter: ListFormatter},
        {key: '_business_company_company_type', label: 'Legal structure'},
        {key: '_business_company_industry', label: 'Industry', formatter: ListFormatter},
        {key: '_business_company_revenue', label: 'Revenue', formatter: ListFormatter},
        {key: '_business_company_operating_income', label: 'Operating income', formatter: ListFormatter},
        {key: '_business_company_market_capitalization', label: 'Market capitalization', formatter: ListFormatter},
        {key: '_business_company_founders', label: 'Founders', formatter: ListFormatter},
        {key: '_business_company_net_income', label: 'Net income', formatter: ListFormatter},
        {key: '_business_company_board_members', label: 'Board members', formatter: ListFormatter},
        {key: '_business_company_major_shareholders', label: 'Major shareholders', formatter: ListFormatter},
        {key: '_business_company_advisors ', label: 'Advisors', formatter: ListFormatter},
        {key: '_business_company_number_of_employees', label: 'Number of employees', formatter: ListFormatter},
        {key: '_business_company_ticker_symbol', label: 'Ticker symbol', formatter: ListFormatter},
        {key: '_business_company_slogan', label: 'Slogan', formatter: ListFormatter},
        {key: '_business_company_previous_names', label: 'Previous names', formatter: ListFormatter},
        {key: '_business_company_parent_company', label: 'Parent company', formatter: ListFormatter},
        {key: '_business_company_subsidiary_companies ', label: 'Subsidiary companies', formatter: ListFormatter},
        {key: '_business_company_spun_off_from', label: 'Spun off from', formatter: ListFormatter},
        {key: '_business_company_spin_offs', label: 'Spin offs', formatter: ListFormatter},
        {key: '_business_company_acquired_by', label: 'Acquired by', formatter: ListFormatter},
        {key: '_business_company_companies_acquired', label: 'Companies acquired', formatter: ListFormatter},
        {key: '_business_company_involved_in_merger', label: 'Involved in merger', formatter: ListFormatter},
        {key: '_business_company_product_of_merger', label: 'Product of merger', formatter: ListFormatter},
        {key: '_business_company_locations', label: 'Business Locations', formatter: ListFormatter},
        {key: '_business_company_divisions', label: 'Divisions', formatter: ListFormatter},
        {key: '_business_company_brands', label: 'Brands', formatter: ListFormatter},
        {key: '_business_company_previous_names', label: 'Product lines', formatter: ListFormatter},
    ];


    var ResultsColumnDefs = [
        {key:'name', label:'Company', formatter: CompanyNameFormatter, width: 250},
        {key:'has_area_of_expertise', label:'Technology Focus', formatter: ListFormatter,sortable:true, width: 150},
        {key:'has_develops_treatments_for_disease', label:'Medical focus', formatter: ListFormatter,sortable:true, width: 150},
        {key:'has_products', label:'Products', formatter: ListFormatter,sortable:true, width: 100},
    ];


    var Results = new YAHOO.util.XHRDataSource('{% url companies_search_ajax "json" %}');
    Results.responseType = YAHOO.util.XHRDataSource.TYPE_JSON;
    Results.responseSchema = {
        resultsList: 'Results',
        fields : [
            { key: 'name' },
            { key: 'id' },
            { key: 'image' },
            { key: 'has_area_of_expertise' },
            { key: 'has_products' },
            { key: 'has_develops_treatments_for_disease' },
            { key: 'website' },
            { key: 'article_head' },
            { key: 'article_tail' },
        ],
    };

    var emptyMessage  = 'Please enter a query above to find information about science and technology companies';
</script>

<!-- Build Yahoo DataTable and filters for search -->
<script type="text/javascript" src="/bvsearchapp/static/js/search_with_yahoo_datatable.js"></script>

<script type="text/javascript">
    $(document).ready(function(){
        /* When user clicks on "Export" button */
        $("#id_button_export").click(function() {
            var loc = '{% url companies_search_ajax "csv" %}' + requestBuilder();
            location.href = loc;
        });

        /* When user clicks on "Share" button */
        $("#id_share_button").click(function() {
            jQuery.facebox('<p style="font-size: 1.2em">Copy following link to share the page:<br/><code>' + location.protocol + '//' + location.host + '/search/companies/' + requestBuilder()+'<\/code><\/p>');
        });
    });
</script>

{% endblock %}

{% block container %}
<div id="bvsearchapp">

<!-- begin: Search block -->
<div class="container" style="width:889px;">
    <div class="c" style="background:#F1F1F1;padding:16px; border: 2px solid #999;">
        <div id="filters_div">
            <span class="large">Find companies by</span>
            <select name="filter_type" class="first filter_type">
                <option value="name">Company name</option>
                <option value="has_area_of_expertise">Technology Focus</option>
                <option value="products">Products</option>
                <option value="has_develops_treatments_for_disease">Medical focus</option>
            </select>
            <input type="text" size="10" name="filter_query" class="filter_query" />
            <input type="button" class="filter_add" value="+"/>
            <input type="button" class="filter_run" name="filter" value="Search" />
            <img src="/static/img/ajax-loader.gif" style="margin-left: .5em; display: none; position: relative; top: 3px;" id="img_loading" alt="Loading..." /><br />
        </div>
    </div>
</div>
<!-- end: Search block -->

<!-- begin: Count of results -->
<p class="results_count">Showing <span id="records_index"></span> <strong id="total_records">0</strong> companies <span id="filters"></span></p>
<!-- end: Count of results -->

<div class="w100p" style="margin-bottom: 1em;">
    <table border="0" cellpadding="0" cellspacing="0" style="width: 100%; margin-top: 1em;" summary="Search">
        <tr valign="middle">
            <td width="50%">
                <a id="id_add_rows" class="u" href="#">Add</a>
                <select id="id_row_to_add" name="row_to_add" style="display: none;"></select>
                <input type="button" name="button_row_add" id="id_button_row_add" value="Add"  style="display: none;"/>
                <span> or </span>
                <a id="id_rm_rows" class="u" href="#">Del</a>
                <select id="id_row_to_rm" name="row_to_rm" style="display: none;"></select>
                <input type="button" name="button_row_rm" id="id_button_row_rm" value="Del"  style="display: none;"/>
                <span> columns?</span>
            </td>
            <td width="50%" class="right">
                <input type="button" name="save" value="Save {% if not request.user.username %}*{% endif %}" id="id_button_save" {% if not request.user.username %}disabled="disabled" {% endif %}/>
                <input type="button" id="id_share_button" name="share" value="Share" />
                <input type="button" name="export" value="Export" id="id_button_export" />
                {% if not request.user.username %}
                <p style="font-size: x-small; color: #999; text-align: right;">* You must  be logged in.</p>
                {% endif %}
           </td>
        </tr>
    </table>
</div>

<div id="results"></div>
<div id="paginated"></div>

<form name="widget" id="widget" method="post" style="display: none;" action="{% url companies_widget %}">
    <textarea name="text" id="input_widget" rows="30" cols="100"></textarea>
</form>

{% if request.user.username %}
<form name="save_as_analysis" id="post_to_analysis" method="post" style="display: none;" action="{% url blog_create request.user.username %}">
    <textarea name="text" id="text" rows="30" cols="100"></textarea>
    <input type="hidden" name="external_data" value="True" /> <!-- If this variable in POST, then new analysis will be filled with POST['text'] data. -->
</form>
{% endif %}

</div>
{% endblock %}
